package logic

import (
	"context"
	"fmt"
	"grpc.getaway.adminspro.padmins.com/internal/rpc/utils/database"
	"grpc.getaway.adminspro.padmins.com/pkg/config/businessError"
	"grpc.getaway.adminspro.padmins.com/pkg/libs/utils"
)

func GetResourceByAdminId(ctx context.Context, resourceIds []int64) ([]map[string]interface{}, *businessError.ErrorInfo) {
	where := ""
	bindValue := []int64{}

	if !utils.InArrayInt64(int64(0), resourceIds) {
		where = "and id in (?)"
		bindValue = resourceIds
	}

	rows, e := database.Db.GetDefaultDb(ctx).Query(fmt.Sprintf("select * from admin_resource where status=1 %s", where), bindValue)

	if e != nil {
		return nil, businessError.DbError(e)
	}

	return rows, nil
}
